package cn.woblog.android.common.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by ren on 2015/5/15 0015.
 */
public class SharePreferenceUtils {
    private static SharePreferenceUtils instance;
    private final SharedPreferences sharedPreferences;

    public SharePreferenceUtils(Context context) {
        sharedPreferences = context.getSharedPreferences(Const.CONFIG_FILENAME, Context.MODE_PRIVATE);
    }

    public static SharePreferenceUtils getInstance(Context context){
        if (instance==null){
            instance = new SharePreferenceUtils(context);
        }
        return instance;
    }

    public void putString(String key,String value){
        save(getEdit().putString(key,value));
    }

    private void save(SharedPreferences.Editor editor) {
        editor.apply();
    }

    private SharedPreferences.Editor getEdit() {
        return sharedPreferences.edit();
    }
}
